<%-- 
    Document   : index
    Created on : 04-dic-2014, 11:52:06
    Author     : equipo_4
--%>

<%@page import="Conexion.Conexion"%>
<%@page import="java.util.List"%>
<%@page import="RRHH_MODELO.RHH_PROFESION"%>
<%@page import="java.util.StringTokenizer"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>BROKER</title>
        <link href="Estilo/estilo.css" rel="stylesheet" type="text/css"/>
         <script src="js/jquery-1.8.2.min.js" type="text/javascript"></script>
         <script src="js/jquery-ui.js" type="text/javascript"></script>
         <script src="js/jquery.ui.touch-punch.js" type="text/javascript"></script>
    </head>
    <body style="background-color: black;">
        <div id='backgroundlogin' style="width: 75%;">
            <img src="img/fondologin.jpg" alt=""/>
        </div>
        <div id="contenedorLogin" >
            <div id="login">
                <div style="margin: 0px auto; height: 40px; width: 170px;">
                    <img src="img/logoBroker.jpg" alt=""/>
                </div>
                <input type="number" value="" name="usr" placeholder="CI" class="grande" style=" display: block; margin: 6px auto;"/>
                <input type="password" value="" name="pass" placeholder="CONTRACEÑA" class="grande" style="display: block; margin: 6px auto;"/>
                <div id="mensage" style="display: none; text-align: center; color: red; font-size: 9px;margin: -6px 0;text-align: center;"></div>
                <button onclick="loguin();" class="grande" style=" display: block; margin: 6px auto;">INGRESAR</button>
                <div style="text-align: center;" >¿Eres nuevo? <a id="registro" href="javascript:void(0)"onclick="ver_Registro();">Registrate</a></div>
                <div style="text-align: center;" >¿Olvidaste tu contraseña?<a href="javascript:void(0)" onclick="reenviar();">Enviar Contraseña</a></div>
            </div>
            <div style="display: none;  height: 145px; width: 232px;" id="cont_registro">
                <div class="negrilla" style="text-align: center;">REGISTRO</div>
                <form id="reg"  method="POST" enctype="multipart/form-data">
                    <div id="mensage2" style="padding-left: 13px; color: red; font-size: 9px;"></div>
                    <input type="number" class="grande" onkeyup="validarCi(this)" name="ci" value="" placeholder="CI" required style=" display: block; margin: 6px auto;"/>
                    <input type="hidden"  name="evento" value="registro"/>
                    <select name="depto"  style="width: 214px; display: block; margin: 6px auto;">
                        <option value="SCZ">SCZ</option>
                        <option value="BN">BN</option>
                        <option value="PND">PND</option>
                        <option value="TRJ">TRJ</option>
                        <option value="CBBA">CBBA</option>
                        <option value="SCR">SCR</option>
                        <option value="LPZ">LPZ</option>
                        <option value="PT">PT</option>
                        <option value="OR">OR</option>
                    </select>
                    <input type="text" class="grande" name="nombre1" value="" placeholder="PRIMER NOMBRE" style=" display: block; margin: 6px auto;"/>
                    <input type="text" class="grande" name="nombre2" value="" placeholder="SEGUNDO NOMBRE" style=" display: block; margin: 6px auto;"/>
                    <input type="text" class="grande" name="apepat" value="" placeholder="PRIMER APELLIDO" style=" display: block; margin: 6px auto;"/>
                    <input type="text" class="grande" name="apemat" value="" placeholder="SEGUNDO APELLIDO" style=" display: block; margin: 6px auto;"/>
                    <input type="email" class="grande" onkeyup="existeRepetido(this,'2')" name="email" value="" placeholder="EMAIL" required style=" display: block; margin: 6px auto;"/>
                    <input type="text" class="grande" name="telf" value="" placeholder="TELEFONO" onkeyup="existeRepetido(this,'1')" style=" display: block; margin: 6px auto;"/>
                    <select name="prof"  style="width: 214px; display: block; margin: 6px auto;">         
                    <%
                        Conexion con = new Conexion();
                        List<RHH_PROFESION> lista = new RHH_PROFESION(con).Todos();
                        for (int i = 0; i < lista.size(); i++) {
                           out.print("<option value='"+lista.get(i).getID()+"'>"+lista.get(i).getDESCRIPCION()+"</option>");
                        }
                    %>                
                    </select>
                    <input type="number" class="grande" value="0" name="anos" placeholder="AÑOS EXPERIENCIA" required style=" display: block; margin: 6px auto;"/>              
                    <div style="text-align: center;">
                        <button onclick="insertar();" type="button">REGISTRAR</button>
                        <a href="javascript:void(0)" onclick="cancel();">CANCELAR</a>
                    </div>
                </form>
            </div>
        </div>
        
            
        <script type="text/javascript">
            $(document).ready(function(){
                left=($(window).width() - $('#contenedorLogin').outerWidth())/2;
                top1=($(window).height() - $('#contenedorLogin').outerHeight())/2;
                $("#backgroundlogin").css("height",$(window).height());
                $("#contenedorLogin").css({
                    left:left ,
                    top: top1 
                });
                
            });
            $(window).resize(function(){
                left=($(window).width() - $('#contenedorLogin').outerWidth())/2;
                top1=($(window).height() - $('#contenedorLogin').outerHeight())/2;
                $("#backgroundlogin").css("height",$(window).height());
                $("#contenedorLogin").css({
                    left:left ,
                    top: top1 
                });
             });
            var url = "loguin";
            function reenviar()
            {
                var usr = $("input[name=usr]").val();
                $("#mensage").css("display","block");
                if(usr.length===0){
                    $("#mensage").html("Introdusca su carnet de identidad");
                    return;
                }
                $.post(url,{evento:"reenviarPass",usr:usr},function (response){
                     $("#mensage").html(response);
                     cancel();
                });                 
            }
            function validarCi(ele){
                var ci=$(ele).val();
                if(ci.length==0){
                    ci=0;
                    $(ele).css("background","#6598ae");
                    return;
                }
                $.post(url,{evento:"validarci",ci:ci},function(responsetext){
                    if(responsetext=="1"){
                        $(ele).css("background","#6598ae");
                        $("#mensage2").html("");
                    }else{
                        $(ele).css("background","red");
                        $("#mensage2").html("-El Carnet de identidad se encuentra registrado");
                    }
                });
            }
            
            function existeRepetido(ele,tipo){
                $.post(url,{evento:"existeRepetido",tipo:tipo,text:$(ele).val()},function(responsetext){
                    if(parseInt(responsetext)>0){
                        $(ele).css("background","red");
                        if(tipo=="2")
                        $("#mensage2").html("-El correo ya se encuentra en uso");
                        if(tipo=="1")
                        $("#mensage2").html("-El telefono ya se encuentra en uso");
                    }else{
                        $(ele).css("background","#6598AE");
                        $("#mensage2").html("");
                    }
                });
            }
            function insertar()
            {           
                var email=$("input[name=email]").val();
                var formData = new FormData($("#reg")[0]);
                 $.ajax({
                        url: url,
                        type: 'POST',
                        data:  formData,
                        mimeType:"multipart/form-data",
                        contentType: false,
                        cache: false,
                        processData:false,
                        success: function(response, textStatus, jqXHR)
                        {
                            if(response=="true")
                            {
                                $("#mensage").html("Su Contraceña fue enviada a "+email);
                                $("#mensage").css("display","block");
                                var ci=$("input[name=ci]").val();
                                     $.post(url,{evento:"reenviarPass",usr:ci},function (response){
                                });
                                cancel();
                            }
                            else
                            {
                                $("#mensage").html("ERROR EN LOS DATOS DE REGISTRO");
                                $("#mensage").css("display","block");
                                cancel();
                            }
                        },
                        error: function(jqXHR, textStatus, errorThrown)
                        {
                            alert("ERROR EN LA TRANSACCION");
                        }         
                    });
            }
            var top1;
            var left;
            function cancel()
            {
                $("#cont_registro").css("display","none");
                $("input").val("");
                $("#login").slideDown("slow",function(){
                    $("#reg")[0].reset();  
                    $("#mensage2").html("");
                });
                $("#contenedorLogin").animate({
                    left: left,
                    top: top1,
                    height: 155
                },"slow");
            }
            
            function ver_Registro()
            {
                $("#cont_registro").css("display","block");
                $("#login").slideUp("slow",function(){
                    $("input[name=usr]").val("");
                    $("input[name=pass]").val("");
                    $("#mensage").css("display","none");
                });
                $("#contenedorLogin").animate({
                   top:35,
                   height:309
                },function(){
                    
                });
            }
                       
            
            function loguin()
            {
                var usr = $("input[name=usr]").val();
                var pass = $("input[name=pass]").val();
                $.post(url,{evento:"logueo",usr:usr,pass:pass},function (response){
                    if(response=="true")
                    {
                        location.href="ppl.jsp";
                    }
                    if(response=="2")
                    {
                        $("#mensage").text("Contraceña Incorrecta");
                        $("#mensage").css("display","block");
                        $("#reenviar").css("display","block");
                        $("#registro").css("display","none");
                    }
                    if(response=="false")
                    {
                        $("#mensage").css("display","block");
                        $("#mensage").text("La cuenta o contraseña es incorecta");
                    }                                        
                });
            }
            
            
        </script>
    </body>
</html>
